package com.springboot_experiment_2.config;

import org.springframework.boot.CommandLineRunner;
import org.springframework.core.env.Environment;

import java.util.Objects;

/**
 * @author:HGF
 */
@SuppressWarnings("unused") // 取消特定代码段（即，类或方法）中的警告
public class CustomCommandLineRunner implements CommandLineRunner {

    Environment env;

    public CustomCommandLineRunner(Environment env) {
        this.env = env;
    }

    @Override
    public void run(String... args) throws Exception {
        System.out.println("利用Spring Boot 自动装配的CommandLineRunner");

        // Spring随机值属性源RandomValuePropertySource 会自动生成32位随机字串
        System.out.println("生成一个随机字符串：".concat(Objects.requireNonNull(env.getProperty("random."))));
    }
}
